home *** CD-ROM | disk | FTP | other *** search
/ QuickTime - The Beta Release / QuickTime - The Beta Release.iso / Programming Stuff / Sample Code / BareBones / Bare Bones Prev.c < prev    next >
C/C++ Source or Header  |  1991-09-05  |  4KB  |  117 lines

  1. /**************************************************
  2. *
  3. * Bare Bones Player (Version That Uses Standard Preview)
  4. *    This program demonstrates how to open a movie file 
  5. *    and play it in a window
  6. *
  7. *     Rich Williams 12/90                Chris Thorman 3/18/91
  8. *        Updated 2/91, 3/91                Updated 3/18/91
  9. *        Updated to 4.04 interfaces
  10. *    Updated to MPW/Think 5.0/DSG interfaces 9/91 Chris Thorman
  11. *        
  12. ***************************************************/
  13.  
  14. #include "Movies.h"
  15.  
  16. #include <Memory.h>
  17. #include <Fonts.h>
  18. #include <OSEvents.h>
  19. #include <Menus.h>
  20.  
  21. /**************************************************
  22. * Variables
  23. ***************************************************/
  24. Movie    theMovie;                    /*    Info about the movie returned by OpenMovie*/
  25. Rect    dispBounds;
  26.  
  27. WindowPtr    movieWindow;            /* Window to play the movie in */
  28. OSErr        theErr;
  29.  
  30. /* Stuff for opening the file */
  31. FSSpec        mySpec;                    /* File System record for the file */
  32. short    resRefNum;                    /* Resource reference number when opening the file */
  33.  
  34. Point        dlgPos = {100,100};        /* Position the dialog box */
  35. short        numtypes = 1;                
  36. SFTypeList    types =    {'MooV'};
  37.  
  38.     
  39. StandardFileReply        sfr;        /* New-style SF reply */
  40.  
  41. void  PlayTheMovie(void);
  42.  
  43. /**************************************************
  44. *
  45. * main()
  46. *    This is where everything happens
  47. *
  48. ***************************************************/
  49. main()
  50. {    
  51.     MaxApplZone();                /* Initialize the managers */
  52.     InitGraf(&qd.thePort);
  53.     InitFonts();
  54.     FlushEvents(everyEvent, 0);
  55.     InitWindows();
  56.     InitMenus();
  57.     InitCursor();
  58.  
  59.     if(theErr = EnterMovies())    /* Start up the movie tools */
  60.         return;                    /* Bail out if error. A nice person would put an alert up */
  61.  
  62.     PlayTheMovie();                /* Do it */
  63.     
  64.     ExitMovies();
  65. }
  66.  
  67. /**************************************************
  68. *
  69. * PlayTheMovie() Opens and plays Movie File
  70. *
  71. ***************************************************/
  72. void 
  73. PlayTheMovie(void)
  74. {
  75.     /* Find out which movie file to play */
  76.  
  77.     StandardGetFilePreview(0, numtypes, types, &sfr);
  78.     if (!sfr.sfGood) return;                /* Return if no selection */
  79.     
  80.     /* No need to make an FSSpec record for the file 
  81.         because StandardGetFilePreview returns one as part of its StandardFileReply */
  82.     
  83.     /* First open the movie file */
  84.     if (theErr = OpenMovieFile(&(sfr.sfFile), &resRefNum, 0))
  85.         return;                                /* Bail out if it didn't work */
  86.  
  87.     if (theErr = NewMovieFromFile( &theMovie,resRefNum, nil, nil,0, nil ))
  88.         return;                                /* Bail out if it didn't work */
  89.  
  90.     /* Get the bounds for the movie  and make sure the top left is 0,0 */
  91.     /* so the movie won't be offset within the window */
  92.     GetMovieBox( theMovie, &dispBounds);
  93.     OffsetRect(&dispBounds,-dispBounds.left,-dispBounds.top);
  94.     SetMovieBox(theMovie, &dispBounds);        
  95.  
  96.     /* Set up the window for the movie to play in */
  97.     OffsetRect(&dispBounds,100,100);            /* Make sure window not under menu bar */
  98.     movieWindow = NewCWindow(0L,&dispBounds,(StringPtr)sfr.sfFile.name,true,0,(WindowPtr)-1L,false,0L);    /* Make a new window */    
  99.     SetPort(movieWindow);
  100.     SetMovieGWorld(theMovie,nil,nil);        /* Play the movie in the window */
  101.     
  102.     /* Now we're ready to play the movie */
  103.     GotoBeginningOfMovie(theMovie);
  104.     PrerollMovie(theMovie,0,0);                /* Get the movie ready to play */
  105.     SetMovieActive(theMovie,true);
  106.     StartMovie(theMovie);                    /* Start the movie */
  107.  
  108.     /* Play the movie until done or the mouse button has been pressed */
  109.     while ( !IsMovieDone(theMovie) && !Button() )
  110.         MoviesTask(theMovie,0);
  111.  
  112.     /* Clean up and go home */
  113.     DisposeMovie(theMovie);                    /* Get rid of the movie */
  114.     CloseMovieFile(resRefNum);
  115. }
  116.  
  117.